import re
from typing import Literal

from pydantic import BaseModel, Field, field_validator
from sqlalchemy import Column, BigInteger, Integer, String, Text
from toollib.utils import now2timestamp

from app.datatype import DeclBase, filter_fields
from app.initializer import g


class UserCollection(DeclBase):
    __tablename__ = "user_collection"

    id = Column(BigInteger, primary_key=True, autoincrement=True, comment="主键")
    user_id = Column(String(20), nullable=True, comment="用户ID")
    milvus_index_id = Column(BigInteger, nullable=True, comment="知识库id")
    is_deleted = Column(BigInteger, default=0, comment="删除状态，0未删除，1已删除")


class UserCollectionCreateMdl(BaseModel):
    user_id: str = Field(default=1, title="用户ID", description="用户ID")
    milvus_index_id: int = Field(default=1, title="知识库ID", description="知识库ID")


class UserCollectionGet(BaseModel):
    user_id: str = Field(default="", title="用户ID", description="用户ID")
    milvus_index_id: int = Field(default=1, title="知识库ID", description="知识库ID")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )
